package com.ruoyi;

import com.ruoyi.common.config.EnvConfig;
import com.ruoyi.manager.SocketChannelManager;
import com.ruoyi.manager.WebSocketChannelManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Timer;
import java.util.TimerTask;

/**
 * 启动程序
 *
 * @author ruoyi
 */
@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableCaching //开启缓存注解功能。
public class WuJiangApplication {
    public static void main(String[] args) {
        // System.setProperty("spring.devtools.restart.enabled", "false");
        ConfigurableApplicationContext applicationContext = SpringApplication.run(WuJiangApplication.class, args);
        String startSuccessHintInfo = "(♥◠‿◠)ﾉﾞ  无疆泡泡豚监控系统启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ";
//        System.out.println(startSuccessHintInfo);
        log.info(startSuccessHintInfo);

        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        int wsHeartBeatDuration = environment.getProperty("miniprogram.wsHeartBeatDuration", Integer.class, 15);
        String active = environment.getProperty("spring.profiles.active");
        EnvConfig envConfig = new EnvConfig();
        envConfig.setWsHeartBeatDuration(wsHeartBeatDuration);
        envConfig.setActive(active);

//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//                //检查及打印当前socket连接情况
//                SocketChannelManager.printCurrentSocketConnectionStatus();
//                log.info("==============分割线=====================");
//                //检查及打印当前WebSocket连接情况。
//                WebSocketChannelManager.printCurrentWebsocketConnectionStatus();
//            }
//        }, 5000, 5000);

//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//                log.trace("打印trace级别测试log!");
//                log.debug("打印debug级别测试log!");
//                log.info("打印info级别测试log!");
//                log.warn("打印warn级别测试log!");
////                log.error("打印error级别测试log!");
//            }
//        }, 5000, 5000);
//
//        new Timer().schedule(new TimerTask() {
//            @Override
//            public void run() {
//                try {
//                    int result = 1 / 0;
//                } catch (Exception e) {
////                    throw new RuntimeException(e);
////                    log.error("打印error级别测试log, e1: {}", e.getMessage());
//                    log.error("打印error级别测试log, e: {}", e.getMessage(), e);
//                }
//
//            }
//        }, 5000, 120000);

    }
}
